/**
 * 
 */
package com.jiang.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.jiang.vo.Dept;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Administrator
 *
 */
@SuppressWarnings("serial")
public class StrutsTagsDemoAction extends ActionSupport {

	private String msg;
	private Dept dept = new Dept();
	
	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Dept getDept() {
		return dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}


	@Override
	public String execute() throws Exception {
		// 如果前端没有传值过来就一定要实例化 Dept dept = new Dept();
		this.msg = "我是直接双向绑定的字符串信息!";
		this.dept.setDeptno(200);
		this.dept.setDname("我是双向绑定的部门名称");
		// 下面使用request属性范围来干
		ServletActionContext.getRequest().setAttribute("info", "request属性范围发出消息 ");
		Dept vo = new Dept();
		vo.setDeptno(300);
		vo.setDname("我是销售部");
		ServletActionContext.getRequest().setAttribute("deptvo", vo);
		// 传递日期参数到前端JSP
		Date date = new Date();
		ServletActionContext.getRequest().setAttribute("mydate", date);
		// 传递一个dept集合给前端JSP, 用Struts2标签直接输出
		List<Dept> depts = new ArrayList<Dept>();
		for(int i=0;i<10;i++){
			Dept dept = new Dept();
			dept.setDeptno(100+i);
			dept.setDname("研发部门"+i);
			depts.add(dept);
		}
		ServletActionContext.getRequest().setAttribute("depts", depts);
		return SUCCESS;
	}

}
